package com.example.algorithm.stack;

import com.example.algorithm.stach.ArrayStack;
import com.example.algorithm.stach.LinkedListStack;
import com.example.algorithm.stach.Stack;

import java.util.Random;

public class StackCompare {

    private static double testStack(Stack<Integer> stack, int opCount) {
        long startTiem = System.nanoTime();

        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            stack.pop();
        }
        long endTime = System.nanoTime();

        return (endTime - startTiem) / 1000000000.0;
    }

    public static void main(String[] args) {
        int opCount = 10000;
        ArrayStack<Integer> arrayStack = new ArrayStack<>();
        double time1 = testStack(arrayStack, opCount);
        LinkedListStack<Integer> linkedListStack = new LinkedListStack<>();
        double time2 = testStack(linkedListStack, opCount);
        System.out.println("Array stack time: " + time1);
        System.out.println("LinkedList stack time: " + time2);
    }
}
